package gui;

import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.net.*;
import java.util.*;
import domein.*;

public class MyPanel extends JPanel {
	private JComboBox		hostField		= new JComboBox();
	private MyTextField	portField		= new MyTextField("12355",5,1);
	private MyTextField	contentField	= new MyTextField(25,2);
	private JLabel			hostText			= new JLabel("host: ");
	private JLabel			portText			= new JLabel("port: ");
	private JLabel			contText			= new JLabel("content: ");
	private JButton		startButton		= new JButton("Start");

	public MyPanel(Control contr) {
		super();
		setLayout(new FlowLayout());
		startButton.setBackground(Color.GREEN);
		
		try {
			InetAddress yourIP=InetAddress.getLocalHost();
			InetAddress address[] = InetAddress.getAllByName(yourIP.getHostName());
			String localAddress[] = new String[address.length];
			
			for(int i = 0; i < address.length; i++) {
				hostField.addItem(address[i].getHostAddress());
			}
		} catch (UnknownHostException e) {
			System.err.println("Unable to lookup ");
		}
		
		Properties p = System.getProperties();
		contentField.setText(p.getProperty("user.dir"));
		
		hostField.addItemListener(contr);
		portField.addActionListener(contr);
		contentField.addActionListener(contr);
		startButton.addActionListener(contr);
		
		add(hostText);
		add(hostField);
		add(portText);
		add(portField);
		add(contText);
		add(contentField);
		add(startButton);
	}
	
	/*
	public int getPort() throws NumberFormatException{
		return Integer.parseInt(portText.getText());
	}
	
	public String getHost(){
		return (String)hostField.getSelectedItem();
	}
	
	public String getContentBase(){
		return contentField.getText();
	}
	*/
}
